package com.yjpark;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Gallery gal = (Gallery) findViewById(R.id.gallery1);
        gal.setAdapter(new ImageAdapter(this));
        
        gal.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        		Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
        		ImageView imgView = (ImageView)findViewById(R.id.imageView1);
        		int imgID = (Integer)parent.getItemAtPosition(position);
        		imgView.setImageResource(imgID);
        	}
        });
    }
}